package com.igl.talk.android.client.core.service;
/*
 * @author Adam Wieczorek 
 *
 * 26/03/2014
 *
 * All rights reserved.
 */

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.Messenger;
import com.igl.talk.android.client.core.handlers.IncomingMessagesHandler;

public class ChatService extends Service {
    private Messenger client;
    private IncomingMessagesHandler serviceHandler = null;

    @Override
    public IBinder onBind(Intent intent) {
        if (client == null) {
            serviceHandler = IncomingMessagesHandler.getInstance(getApplicationContext());
            serviceHandler.setApplicationStopped(false);
            client = new Messenger(serviceHandler);
        }
        return client.getBinder();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        serviceHandler.setApplicationStopped(true);
        return super.onUnbind(intent);
    }
}
